using System;
using System.Collections.Generic;
using System.Text;
using MacomberMap.Common.User_Interfaces.Components;
using System.Drawing;
using System.Windows.Forms;
using MacomberMap.Common.Components;
using System.ComponentModel;
using MacomberMap.Common.Types;
using System.Xml;

namespace MacomberMap.Common.User_Interfaces.One_Lines.Elements
{
    /// <summary>
    /// This class holds information on a pricing vector
    /// </summary>
    public class MM_OneLine_PricingVector: MM_OneLine_PokePoint
    {
        #region Variable declarations
  
        /// <summary>The EPS meter associated with the vector</summary>
        [Category("Display"), Description("The EPS meter associated with the pricing vector")]
        public MM_EPSMeter EPSMeter
        {
            get { return (BaseElement as MM_PricingVector).EPSMeter; }
            set { (BaseElement as MM_PricingVector).EPSMeter = value; }
        }
        

        /// <summary>
        /// The resource ID of the pricing vector
        /// </summary>
        [Category("Display"),Description("The resource ID of the pricing vector")]
        public string RID
        {
            get { return (BaseElement as MM_PricingVector).EPSMeter.RID; }            
        }
        

        /// <summary>Whether the flow towards the associated node is positive</summary>
        [Category("Display"), Description("Whether the flow towards the associated node is positive")]
        public bool IsPositive
        {
            get { return (BaseElement as MM_PricingVector).IsPositive; }
            set { (BaseElement as MM_PricingVector).IsPositive = value; }
        }        
        #endregion

        #region Initialization
        /// <summary>
        /// Initialize a new pricing vector
        /// </summary>
        /// <param name="PricingVector">The pricing vector</param>
        /// <param name="DisplayParams">The display parameters</param>
        /// <param name="Orientation">The orientation of the pricing vector</param>        
        public MM_OneLine_PricingVector(MM_Element PricingVector, MM_OneLine_Display DisplayParams, enumOrientations Orientation)
            : base(PricingVector, null, DisplayParams, Orientation, false, true)
        {
        }

        /// <summary>
        /// Initialize a new pricing vector
        /// </summary>
        /// <param name="PricingVector">The pricing vector</param>
        /// <param name="DisplayParams">The display parameters</param>
        /// <param name="Orientation">The orientation of the pricing vector</param>
        /// <param name="BaseNode">The node associated with the pricing vector</param>
        public MM_OneLine_PricingVector(MM_Element PricingVector, MM_OneLine_Node BaseNode, MM_OneLine_Display DisplayParams, enumOrientations Orientation)
            : base(PricingVector, BaseNode, DisplayParams, Orientation, false, true)
        {                     
        }

        /// <summary>
        /// Create a new 
        /// </summary>
        /// <param name="xElem"></param>
        /// <param name="BaseNode"></param>
        /// <param name="DisplayParams"></param>
        public MM_OneLine_PricingVector(XmlElement xElem, MM_OneLine_Node BaseNode, MM_OneLine_Display DisplayParams)
            : base(BaseNode.BaseElement, BaseNode, DisplayParams, enumOrientations.Unknown, false, true)
        {            
            MM_Serializable.ReadXml(xElem, this);
            this.BaseNode = BaseNode;
            this.DisplayParameters = DisplayParameters;
        }
        #endregion

        #region Rendering
        /// <summary>
        /// Draw the image for the pricing vector
        /// </summary>
        /// <param name="g"></param>
        public override void DrawImage(Graphics g)
        {
            //First, draw our rectangle
            using (SolidBrush BackBrush = new SolidBrush(BackColor))
                g.FillRectangle(BackBrush, 0, 0, DisplayRectangle.Width - 1, DisplayRectangle.Height - 1);

            
            MM_KVLevel KVLevel = BaseNode == null || BaseNode.KVLevel == null ? MM_Overall_Display.FindKVLevel("Other KV") : BaseNode.KVLevel;


            g.DrawRectangle(KVLevel.Energized.ForePen, 0, 0, DisplayRectangle.Width - 1, DisplayRectangle.Height - 1);

            //Then, draw our arrow as appropriate
            using (Pen p = new Pen(KVLevel.Energized.ForeColor, 3f))            
            {
                if (IsPositive)
                    p.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;
                else
                    p.StartCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor;

                
                if (Orientation == enumOrientations.Left || Orientation == enumOrientations.Horizontal || Orientation == enumOrientations.Unknown)
                    g.DrawLine(p, Width - 3, Height / 2, 3, Height / 2);
                else if (Orientation == enumOrientations.Right)
                    g.DrawLine(p, 3, Height / 2, Width - 3, Height / 2);
                else if (Orientation == enumOrientations.Up || Orientation == enumOrientations.Vertical)
                    g.DrawLine(p, Width / 2, Height - 3, Width / 2, 3);
                else if (Orientation == enumOrientations.Down)
                    g.DrawLine(p, Width / 2, 3, Width / 2, Height - 3);
            }
        }
        
        
        #endregion
    }
}
